#!/bin/bash

# 初始化元数据
function initialize_cluster_metadata(){
  cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/
  bin/pulsar initialize-cluster-metadata \
  --cluster pulsar-service-1 \
  --zookeeper 10.153.66.129:2181 \
  --configuration-store 10.153.66.129:2181 \
  --web-service-url http://10.153.66.129:8080 \
  --web-service-url-tls https://10.153.66.129:8443 \
  --broker-service-url pulsar://10.153.66.129:6650 \
  --broker-service-url-tls pulsar+ssl://10.153.66.129:6651
  # 接着初始化bookkeeper集群：若出现提示输入Y/N：请输入Y
  echo "y" | bin/bookkeeper shell metaformat
#  cd /app/pmapp/data/rongshu/apache-zookeeper-3.8.4-bin/bin/ && sh zkCli.sh
#  ls /
#  echo "ls /"
#  quit
}

function init_bookie() {
    cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/
    bin/pulsar-daemon start bookie
    echo "验证bookie是否启动启动成功"
    bin/bookkeeper shell bookiesanity
    #echo "`grep success bin/bookkeeper shell bookiesanity`"
}

function init_broker() {
    cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/
    bin/pulsar-daemon start broker
    bin/pulsar-admin brokers list test-pulsar-cluster
    #echo "`bin/pulsar-admin brokers list test-pulsar-cluster`"
}

function init_proxy() {
    cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/
    bin/pulsar-daemon start proxy
}

function init_pulsar_manager() {
    cd /app/pmapp/data/rongshu/apache-pulsar-2.10.6/pulsar-manager/pulsar-manager
    nohup bin/pulsar-manager > pulsar-manager.log 2>&1 &
    sleep 10s
    echo "sh initAccount.sh"
    echo -e "pulsar_manager平台访问链接: \c"
    info "https://10.91.37.48:7750/ui/index.html"
}

function pulsar_a(){
  initialize_cluster_metadata
  init_bookie
  init_broker
  init_proxy
  init_pulsar_manager
}

#function pulsar_b(){
#
#}
#
#function pulsar_c(){
#
#}

# 如何使用
#case $1 in
#1)
  pulsar_a
;;
#2)
#  pulsar_b
#;;
#3)
#  pulsar_c
#;;
#*)
#echo "pulsar_a集群节点配置文件修改 $0 1(节点a)/2(节点b)/3(节点c)"
#;;
#esac
